package speech;

import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;

public class HelloWorld {
	public static void listAllVoices(VoiceManager voiceManager) {
		Voice[] voices = voiceManager.getVoices();
		for (int i = 0; i < voices.length; i++) {
			System.out.println(voices[i].getName() + " (" + voices[i].getDomain() + " domain)");
		}
	}

	public static void main(String[] args) {
		String voiceName = (args.length > 0) ? args[0] : "kevin16";
		new HelloWorld().run(voiceName);
	}

	private void run(String voiceName) {
		VoiceManager voiceManager = VoiceManager.getInstance();

		listAllVoices(voiceManager);

		System.out.println("Using voice: " + voiceName);

		Voice helloVoice = voiceManager.getVoice(voiceName);

		if (helloVoice == null) {
			System.err.println("Cannot find a voice named " + voiceName + ".  Please specify a different voice.");
			System.exit(1);
		}

		helloVoice.allocate();

		helloVoice.speak("Are you sleepy?.");

		helloVoice.deallocate();
	}
}
